const __AppBaseInfo = {
	AppName:"舜通电力运维",
	AppDesc:"舜通电力运维，打造智慧、节能、安全的综合能源平台",
	AppVersion:"1.0.0",
	home:"主页",
	msg:"消息",
	settings:"我的"
}

const constValue = {
	sysId:"SITCAPP",
	token:"token",
	autoLogin:"autoLogin",
	userName:"userName",
	passWord:"passWord",
	autoLogin:"accountDetail",
	url:"URL",
	svgurl:"SVGURL"
}

var Urls = {
	login:"appsys",
	stations:"dcsStation/getStationForSelect"
}

var getToken=function(){
	return localStorage.getItem(constValue.token);
}

var getUrl=function(){
	var url = localStorage.getItem(constValue.url);
	if(url && url!=null){
		return url;
	}else {
		return '';
	}
}

var setUrl=function(url){
	localStorage.setItem(constValue.url,url);
}


var getSvgUrl=function(){
	var url = localStorage.getItem(constValue.svgurl);
	if(url && url!=null){
		return url;
	}else {
		return '';
	}
}

var setSvgUrl=function(url){
	localStorage.setItem(constValue.svgurl,url);
}

var services = {
	login:function(userName,password){
		return new Promise(function(resolve, reject) {
			var baseUrl = getUrl();
			if(baseUrl==""){
				mui.toast("请设置登录地址!")
				reject("baseUrl为空!");
			}
			mui.ajax(baseUrl + Urls.login, {
				data: {
					sysId: constValue.sysId,
					username: userName,
					password: password
				},
				dataType: "json",
				type: 'post',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded',
				},
				success: function(data) {
					resolve(data);
				},
				error: function(error) { 
					reject(error);	
				}
			});
		});
	},
	getStations:function(){
		return new Promise(function(resolve, reject) {
			var baseUrl = getUrl();
			mui.ajax(baseUrl + Urls.stations, {
				data: {
					sysId: constValue.sysId,
					token: getToken()
				},
				dataType: "json",
				type: 'post',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded',
				},
				success: function(data) {
					resolve(data);
				},
				error: function(error) { 
					reject(error);	
				}
			});
		});
	}
	
}



function getViewPortInfos(){ 
	var s = ""; 
	s = s+ "网页可见区域宽：" +document.body.clientWidth+"\n"; 
	s = s+" 网页可见区域高：" +document.body.clientHeight+"\n";  
	s = s+" 网页可见区域宽：" +document.body.offsetWidth+"\n";  
	s = s+" 网页可见区域高：" +document.body.offsetHeight+"\n"; 
	s = s+" 网页正文全文宽：" +document.body.scrollWidth+"\n"; 
	s = s+" 网页正文全文高：" +document.body.scrollHeight+"\n"; 
	s = s+" 网页被卷去的高(ff)：" +document.body.scrollTop+"\n"; 
	s = s+" 网页被卷去的高(ie)：" +document.documentElement.scrollTop+"\n"; 
	s = s+" 网页被卷去的左：" +document.body.scrollLeft+"\n"; 
	s = s+" 网页正文部分上：" +window.screenTop+"\n";  
	s = s+" 网页正文部分左：" +window.screenLeft+"\n";  
	s = s+" 屏幕分辨率的高：" +window.screen.height+"\n";  
	s =s+" 屏幕分辨率的宽：" +window.screen.width+"\n";  
	s = s+" 屏幕可用工作区高度：" +window.screen.availHeight+"\n";  
	s = s+" 屏幕可用工作区宽度：" +window.screen.availWidth+"\n"; 
	s = s+" 你的屏幕设置是 " +window.screen.colorDepth +" 位彩色"+"\n"; 
	s = s+" 你的屏幕设置 " +window.screen.deviceXDPI +" 像素/英寸"+"\n"; 
	
	console.log(s);
}

/**
 * 动态加载JS
 * @param {string} url 脚本地址
 */
function dynamicLoadJs(url, callback) {
	var head = document.getElementsByTagName('head')[0];
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = url;
	if(typeof(callback)=='function'){
		script.onload = script.onreadystatechange = function () {
			if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"){
				callback();
				script.onload = script.onreadystatechange = null;
			}
		};
	}
	head.appendChild(script);
}

/**
 * 动态加载CSS
 * @param {string} url 样式地址
 */
function dynamicLoadCss(url) {
	var head = document.getElementsByTagName('head')[0];
	var link = document.createElement('link');
	link.type='text/css';
	link.rel = 'stylesheet';
	link.href = url;
	head.appendChild(link);
}